package com.shgbit.tdd.marsrover;

/**
 * @author liuyong
 * @date 2020/4/12 14:52
 */
public class MarsRover {

    private Position posotion;
    private Mars mars;

    public Position getPosition() {
        return this.posotion;
    }


    public void landing(Mars mars, Position position) {
        this.mars = mars;
        if (mars.getLength() < position.getX() || mars.getWidth() < position.getY()) {
            throw new IllegalArgumentException("错误的登陆位置");
        }
        this.posotion = position;
    }

    public void explore(String exploreCommand) {
        if (!exploreCommand.matches("^[f|b|l|r]*$")) {
            throw new IllegalArgumentException("错误的操作指令");
        }
        for (char command : exploreCommand.toCharArray()) {
            CommandEnum.valueOf(String.valueOf(command).toUpperCase()).execCommmad(this.posotion,this.mars);
        }
    }
}
